from django.db import models
from api.user_management.models import User
import django.utils.timezone as timezone


class Subject(models.Model):
    """
    课题model，定义了课题相关属性
    """
    subject_id = models.AutoField(max_length=20, primary_key=True, unique=True,
                                  verbose_name='subject_id')  # 课题id
    subject_name = models.TextField(null=False, blank=True,
                                    verbose_name='subject_name')  # 课题名称
    subject_type = models.TextField(null=False, blank=True,
                                    verbose_name='subject_type')  # 课题类型
    subject_keyword = models.TextField(null=False, blank=True,
                                       verbose_name='subject_keyword')  # 关键字
    subject_principal = models.ForeignKey(User, related_name='principal5', on_delete=models.CASCADE, default='')  # 责任人
    subject_participant = models.ManyToManyField(User, related_name='participant5', default='')  # 参与人，可多选
    add_date = models.DateTimeField(default=timezone.now)  # 保存时间
    mod_date = models.DateTimeField(auto_now=True)  # 最后修改时间

    class Meta:
        db_table = 'subject'  # 内嵌类指定课题表表名
        # 权限设置
        default_permissions = ()
        permissions = (
            ('view_subject', u'查看课题'),
            ('add_subject', u'添加课题'),
            ('delete_subject', u'删除课题'),
            ('change_subject', u'修改课题'),
        )
